package infrastructure;

import java.net.NoRouteToHostException;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.net.ConnectException;

public final class ExceptionHandler {
	
	private ExceptionHandler(){
		
	}
	
	/**
	 * Handles the exception
	 * @param ex
	 */
	public static void Handle(Exception ex)
	{
		// We may handle the exceptions: Creating our own exception class
		// or we may distinguish among all the possible exceptions that the app could throw.
		if( ex.getClass() == CommunicationCustomException.class ){
			System.out.println(ex.getMessage());
		} else if( ex.getClass() == UnknownHostException.class){
			System.out.println("Invalid Host " + ex.getMessage());
		} else if (ex.getClass() == IllegalArgumentException.class){
			System.out.println("Invalid Port Value " + ex.getMessage());
		} else if (ex.getClass() == NoRouteToHostException.class){
			System.out.println("Network seems to be not available: " + ex.getMessage());
		} else if( ex.getClass() == ConnectException.class || ex.getClass() == SocketException.class){
			System.out.println("Connection can not be established: " + ex.getMessage());
		}
		else{
			System.out.println(ex.toString());	
		}
	}
}
